/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Administration;

import java.beans.Statement;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.AdminData;
import model.CustomerBean;
import model.DatabaseConnection;

/**
 *
 * @author Dalia.Aly
 */
public class ViewProfileDetails extends HttpServlet {

   private Connection conn;
    private Statement stmt;
    private ResultSet result;
    private PreparedStatement prepStmt;
    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
    {
        String sId = request.getParameter("id");
        int id = Integer.parseInt(sId);
           DatabaseConnection connection= new DatabaseConnection();
           CustomerBean customer;
           ArrayList<CustomerBean> customerData = new ArrayList();
           conn = connection.startConnection();
       try {
           String sql = "SELECT firstName,lastName,birthdate,email,Mobile,address,c_img from customer WHERE c_id=?";
           PrintWriter out = response.getWriter();
           prepStmt = conn.prepareStatement(sql);
           prepStmt.setInt(1, id);
           result = prepStmt.executeQuery();
           while (result.next()) {
               customer = new CustomerBean();
               customer.setFirstName(result.getString("firstName"));
               customer.setLastName(result.getString("lastName"));
               customer.setUserBDate(result.getString("birthdate"));
               customer.setUserMail(result.getString("email"));
               customer.setUserMobile(result.getString("Mobile"));
               customer.setUserAddress(result.getString("Address"));
               customer.setC_img(result.getString("c_img"));
               customerData.add(customer);
           }
//           for(CustomerBean cust:customerData)
//           {
//               out.println(cust.getFirstName());
//           }
           request.setAttribute("profileDetails", customerData);
           RequestDispatcher dispatcher = request.getRequestDispatcher("ViewCustProfileDetails.jsp");
            dispatcher.forward(request, response);
       } catch (SQLException ex) {
           Logger.getLogger(ViewProfileDetails.class.getName()).log(Level.SEVERE, null, ex);
       }
        
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}